package com.margo.project.web.mvcconfig.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.margo.project.web.mvcconfig.model.MargoArgumentResolverVO;
import com.margo.project.web.mvcconfig.model.MargoMvcConfigVO;
import com.margo.project.web.utils.ResultUtils;
import com.margo.project.web.utils.ResultVO;

import io.swagger.annotations.ApiOperation;

@Controller
@RequestMapping("/argumentResolver")
public class MargoArgumentResolverController {

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@ApiOperation(value = "@ModelAttribute注解", notes = "@ModelAttribute注解传参", produces = "application/x-www-form-urlencoded")
	@PostMapping("/modelAttribute")
	@ResponseBody
	public ResultVO modelAttribute(@ModelAttribute MargoArgumentResolverVO margoArgumentResolver) {
		logger.info(margoArgumentResolver.toString());
		return ResultUtils.success(1);
	}
	
	/**
	 * 	应该不支持这种方式
	 * @param margoArgumentResolver
	 * @return
	 */
	@ApiOperation(value = "@RequestParam注解", notes = "@RequestParam注解传参", produces = "application/x-www-form-urlencoded")
	@PostMapping("/objectRequestParam")
	@ResponseBody
	public ResultVO objectRequestParam(@RequestParam MargoArgumentResolverVO margoArgumentResolver) {
		logger.info(margoArgumentResolver.toString());
		return ResultUtils.success(1);
	}

	@ApiOperation(value = "@RequestParam注解", notes = "@RequestParam注解传参", produces = "application/x-www-form-urlencoded")
	@PostMapping("/requestparam")
	@ResponseBody
	public ResultVO requestparam(@RequestParam("name") String name, @RequestParam("age") int age) {
		logger.info("name:" + name + "|age:" + age);
		return ResultUtils.success(1);
	}

	@ApiOperation(value = "发送", notes = "注解传参", produces = "application/x-www-form-urlencoded")
	@PostMapping("/union/{name}")
	@ResponseBody
	public ResultVO union(@RequestParam("name") String name, @RequestParam("age") int age, @PathVariable("name") String id,
			@RequestParam("workStatus") String workStatus, @ModelAttribute MargoMvcConfigVO margoMvcConfigVO) {
		logger.info("name:" + name + "|age:" + age+"|workStatus:"+workStatus);
		logger.info(margoMvcConfigVO.toString());
		logger.info("id:"+id);
		return ResultUtils.success(1);
	}
	
	@ApiOperation(value = "@PathVariable注解", notes = "url传参", produces = "application/x-www-form-urlencoded")
	@PostMapping("/load/{name}")
	@ResponseBody
	public ResultVO pathVariable(@PathVariable("name") String id) {
		logger.info("id:" + id);
		return ResultUtils.success(1);
	}
}
